{% extends "base.html" %}
{% block body %}
<div style="margin-top:5px" class="card border border-dark shadow bg-card-body" id="payloads_table" >
    <div class="card-header shadow border border-dark bg-header text-white">
        <h2 style="display:inline-block">Created <span class="operator">Payloads</span></h2>
        <button style="float:right" class="btn btn{{config['outline-buttons']}}danger btn-md" onclick="delete_selected_function()">Delete all Selected</button>
        <template v-if="view_auto_generated">
            <button style="float:right" class="btn btn{{config['outline-buttons']}}info btn-md" @click="toggle_auto_generated()">Hide Ephemeral</button>
        </template>
        <template v-else>
            <button style="float:right" class="btn btn{{config['outline-buttons']}}success btn-md" @click="toggle_auto_generated()">Show Ephemeral</button>
        </template>

    </div>
        <table class="table table-condensed table-striped {{config['table-color']}} border border-dark shadow" style="margin-bottom:0">
            <tr>
                <th style="width:6rem;text-align:left"><input type="checkbox" id="selectAllForDelete">&nbsp;<b>Delete</b></th>
                <th style="width:6rem"><b>Actions</b></th>
                <th style="width:6rem;text-align:left"><b>Download</b></th>
                <th style="width:8rem"><b>Build Status</b></th>
                <th onclick="sort_table(this)" style="text-align:left"><b>File</b></th>
                <th onclick="sort_table(this)" style="text-align:left"><b>Description</b></th>
                <th onclick="sort_table(this)" style="text-align:left;width:10rem"><b>Creator</b></th>
                <th onclick="sort_table(this)" style="text-align:center;width:10rem"><b>Payload Type</b></th>
                <template v-if="view_auto_generated">
                    <th onclick="sort_table(this, 'int')" style="text-align:center;width:10rem">
                        <b>Task</b>
                    </th>
                </template>
                <th style="width:12rem;text-align:center" onclick="sort_table(this, 'date')"><b>Creation Time</b></th>
            </tr>
        <!-- Repeat this for each payload -->
            <tr v-for="p in payloads" :key="p.creation_time" v-show="p.auto_generated == false || view_auto_generated">
                <td style="text-align:center">
                    <input style="padding-right:10px" type="checkbox" v-model="p.checked"> <button type="button" class="btn btn{{config['outline-buttons']}}danger btn-sm" @click="delete_button(p)" ><i class="fas fa-trash-alt"></i></button>
                </td>
                <td style="text-align:center">
                        <div class="dropdown" style="display:inline">
                            <button class="btn btn{{config['outline-buttons']}}secondary dropdown-toggle btn-sm" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"  :data-target="p.uuid">
                            <i class="fas fa-edit"> Payload Actions</i>
                          </button>
                          <div class="dropdown-menu" :id="p.uuid">
                              <template v-if="!p.auto_generated">
                                  <button type="button" class="dropdown-item" @click="edit_filename(p)">Rename File</button>
                                  <button type="button" class="dropdown-item" @click="edit_description(p)">Edit Description</button>
                                  <button type="button" class="dropdown-item" @click="update_callback_alert(p)">
                                      <template v-if="p.callback_alert">Stop Alerting to new Callbacks</template>
                                      <template v-else>Start Alerting to new Callbacks</template>
                                  </button>
                              </template>
                              <button type="button"  class="dropdown-item" @click="show_parameters_button(p, 'config')">View Config</button>
                              <button type="button" class="dropdown-item" @click="show_parameters_button(p, 'message')">View Build Message</button>
                              <button type="button" class="dropdown-item" @click="show_parameters_button(p, 'stdout')">View Build Output</button>
                              <button type="button" class="dropdown-item" @click="show_parameters_button(p, 'stderr')">View Build Errors</button>
                              <button type="button" class="dropdown-item" @click="build_again(p)">Trigger New Build</button>
                              <button type="button" class="dropdown-item" @click="export_config(p)">Export Payload Config</button>
                              <button type="button" class="dropdown-item" @click="redirect_rules(p)">Generate Redirect Rules</button>
                              <button type="button" class="dropdown-item" @click="config_check(p)">Check Agent C2 Configuration Again</button>
                          </div>
                        </div>

		        </td>
                <td style="text-align:center">
                    <template v-if="p.deleted || p.build_phase !== 'success' || p.auto_generated">
                        <button data-toggle="tooltip" title="Payload failed to build in" class="btn btn{{config['outline-buttons']}}danger btn-sm" disabled type="button"><i class="fas fa-ban fa-lg"></i></button>
                    </template>
                    <template v-else>
                        <a data-toggle="tooltip" title="Payload built successfully" class="btn btn{{config['outline-buttons']}}success btn-sm" :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}{{links.api_base}}/payloads/download/' + p.uuid"><i class="fas fa-download fa-lg"></i></a>
                    </template>
                    </td>
                <td style="text-align:center">
                    <div v-if="p.build_phase == 'success'">
                        <button disabled data-toggle="tooltip" title="Payload built successfully" type="button" class="btn btn{{config['outline-buttons']}}success btn-sm"><i class="fas fa-check-circle fa-lg"></i></button>
                    </div>
                    <div v-else-if="p.build_phase == 'error'">
                        <button data-toggle="tooltip" title="Payload failed to build, check build_error for more information" type="button" disabled class="btn btn{{config['outline-buttons']}}danger btn-sm"><i class="fas fa-exclamation-triangle fa-lg"></i></button>
                    </div>
                    <div v-else>
                        <div data-toggle="tooltip" title="Payload is currently building" class="spinner-border text-info" role="status"></div>
                    </div>
                </td>
                <td>[[ p['file']['filename'] ]]</td>
                <td>[[ p.tag ]]</td>
                <td>[[ p.operator ]]</td>
                <td style="text-align:center">[[ p['payload_type'] ]]</td>
                <template v-if="view_auto_generated">
                    <td style="text-align:center">
                        <template v-if="p.task !== null">
                            <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + p['task']['id']" target="_blank">[[ p['task']['id'] ]]</a>
                        </template>
                    </td>
                </template>
                <td style="text-align:center">[[ toLocalTime(p.creation_time) ]]</td>
            </tr>
        <!-- End of the repeating -->
        </table>
</div>

<!-- THIS IS OUR MODAL FOR DELETING PAYLOAD -->
<div class="modal fade" id="payloadDeleteModal" role="dialog">
    <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3 id="modalLabel">Are you sure?</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button class="btn btn{{config['outline-buttons']}}danger" data-dismiss="modal" id="payloadDeleteSubmit">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR DELETING PAYLOAD -->
<!-- THIS IS OUR MODAL FOR EDITING FILENAME -->
<div class="modal fade" id="payloadEditModal" role="dialog">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3 >[[ header_message ]]</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-body">
                  <input class="form-control" id="payloadEdit" type="text" v-model="edit_value" :value="edit_value" @keyup.enter="$('#payloadEditSubmit').click()">
              </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button class="btn btn{{config['outline-buttons']}}primary" data-dismiss="modal" id="payloadEditSubmit">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR EDITING FILENAME -->
<!-- THIS IS OUR MODAL FOR GETTING PAYLOAD CONFIG -->
<div class="modal fade" id="payloadConfigModal" role="dialog">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>Viewing payload configuration</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            <div class="modal-body" >
                <button disabled class="btn-md btn btn{{config['outline-buttons']}}info" style="width:100%">
                    <template v-if="config.wrapped">Wrapped</template> Command Selection</button>
              <table class="table table-striped {{config['table-color']}}" style="table-layout:fixed;word-wrap: break-word">
                    <tr v-if="config.commands != undefined" align="center">
                        <th><b>Loaded Commands</b></th>
                        <th style="text-align:center"><b>Loaded Version</b></th>
                        <th style="text-align:center"><b>Mythic Version</b></th>
                    </tr>
                  <tr v-for="c in config.commands" v-if="config.commands != undefined" :style="c.version != c.mythic_version ? 'background-color:{{config.failure_highlight}}' : ''">
                      <td style="padding-left:10px">[[c.cmd]]</td>
                      <td style="text-align:center">[[c.version]]</td>
                      <td style="text-align:center">[[c.mythic_version]]</td>
                  </tr>
              </table>
                <template v-for="(value, key) in config.c2_profiles">
                    <button disabled class="btn-md btn btn{{config['outline-buttons']}}info" style="width:100%">
                        <template v-if="config.wrapped">Wrapped</template> [[key]] C2 Profile</button>
                    <table class="table table-striped {{config['table-color']}}" style="table-layout:fixed;word-wrap: break-word">
                        <tr>
                            <th style="width:30%"><b>C2 Profile Param Name</b></th>
                            <th><b>C2 Profile Param Value</b></th>
                          </tr>
                          <tr v-for="p in value">
                              <td style="padding-left:10px">[[p.description]]</td>
                              <td>[[p.value]]
                              <template v-if="p.enc_key"><br>Encryption Key: [[p.enc_key]]</template>
                              <template v-if="p.dec_key"><br>Decryption Key: [[p.dec_key]]</template>
                              </td>
                          </tr>
                    </table>
                </template>
                <button v-if="config.wrapped" disabled class="btn-md btn btn{{config['outline-buttons']}}info" style="width:100%">Wrapped Payload Type Configuration</button>
            <table v-if="config.wrapped" class="table table-striped {{config['table-color']}}" style="table-layout:fixed;word-wrap: break-word">
                <tr>
                    <th style="width:30%"><b>Payload Configuration</b></th>
                    <th><b>Payload Value</b></th>
                  </tr>
                  <tr v-for="p in config.wrapped.build_parameters">
                      <td style="padding-left:10px">[[p.build_parameter.description]]</td>
                      <td>[[p.parameter]]</td>
                  </tr>
                <tr>
                      <td style="padding-left:10px">Build Message</td>
                      <td >[[config.wrapped.build_message]]</td>
                  </tr>
                  <tr>
                      <td style="padding-left:10px">UUID</td>
                      <td >[[config.wrapped.uuid]]</td>
                  </tr>
            </table>
            <button disabled class="btn-md btn btn{{config['outline-buttons']}}info" style="width:100%">Payload Type Configuration</button>
            <table class="table table-striped {{config['table-color']}}" style="table-layout:fixed;word-wrap: break-word">
                <tr>
                    <th style="width:30%"><b>Payload Configuration</b></th>
                    <th><b>Payload Value</b></th>
                  </tr>
                  <tr v-for="p in config.build_parameters">
                      <td style="padding-left:10px">[[p.build_parameter.description]]</td>
                      <td>[[p.parameter]]</td>
                  </tr>
                <tr>
                      <td style="padding-left:10px">Selected OS</td>
                      <td >[[config.selected_os]]</td>
                  </tr>
                  <tr>
                      <td style="padding-left:10px">UUID</td>
                      <td >[[config.uuid]]</td>
                  </tr>
                  <tr>
                      <td style="padding-left:10px">MD5</td>
                      <td >
                          <template v-if="config.file!==undefined">[[config.file.md5]]</template>
                      </td>
                  </tr>
                <tr>
                      <td style="padding-left:10px">SHA1</td>
                      <td >
                          <template v-if="config.file!==undefined">[[config.file.sha1]]</template>
                      </td>
                  </tr>
                <tr>
                    <td style="padding-left:10px">Download File ID</td>
                      <td >
                          <template v-if="config.file!==undefined">
                              [[config.file.agent_file_id]]<br>
                              <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}{{links.api_base}}/files/download/' + config.file.agent_file_id">
                                  {{http}}://{{links.server_ip}}:{{links.server_port}}{{links.api_base}}/files/download/[[ config.file.agent_file_id  ]]
                              </a>
                          </template>
                      </td>
                </tr>
            </table>
            </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal">Close</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR GETTING PAYLOAD CONFIG -->
<!-- THIS IS OUR MODAL FOR DISPLAYING BUILD STATUS -->
<div class="modal fade" id="payloadBuildStatusModal" role="dialog">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>Build Information</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            <div class="modal-body">
                <pre id="buildStatus"></pre>
            </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}info" data-dismiss="modal" aria-hidden="true">Close</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR DISPLAYING BUILD STATUS -->


{% endblock %}

{% block scripts %}
{% include "payload_management.js" %}
{% endblock %}

{% block body_config %}

{% endblock %}